package com.wsoft.cms.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.cms.query.comment.CommentListInfoQuery;
import com.wsoft.cms.query.comment.CommentListQuery;
import com.wsoft.cms.query.comment.CommentMainListQuery;
import com.wsoft.cms.service.ICmsAnnouncementCommentService;
import com.wsoft.cms.vo.comment.CommentVO;
import com.wsoft.cms.vo.comment.MainCommentVO;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 公告评价表 前端控制器
 * @author Z001
 * @since 2024年11月27日 10:37:58
 */
@RestController
@Tag(name = "评论")
@RequestMapping("/cms/comment")
public class CmsAnnouncementCommentController {

    @Resource
    private ICmsAnnouncementCommentService commentService;



    @Operation(summary = "获取评论列表-后台", description = "获取评论列表-后台")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody CommentListInfoQuery query) {
        return ResponseResult.success(ResponsePage.restPage(commentService.listCommon(query)));
    }

    @Operation(summary = "获取主评论的子评论列表-后台", description = "获取主评论的子评论列表")
    @PostMapping("/getChildPage")
    public ResponseResult getChildPage(@RequestBody CommentListQuery query) {
        PageInfo<CommentVO> page = commentService.getChildCommentPage(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }

    @Operation(summary = "获取主评论-后台", description = "获取主评论")
    @PostMapping("/getMainPage")
    public ResponseResult getMainPage(@RequestBody CommentMainListQuery query) {
        PageInfo<MainCommentVO> page = commentService.getMainCommentPage(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }

    @Operation(summary = "删除评论-后台", description = "删除评论")
    @GetMapping("/deleteComment")
    public ResponseResult delete(@RequestParam("id") Long id) {
        return ResponseResult.success(commentService.deleteComment(id,false));
    }


}
